package com.example.blade.cavasapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;

public class CanvasActivity extends AppCompatActivity {

    private ImageButton btnBackward, btnForward, btnClear, btnSave, btnEraser;

    private CustomCanvas mCanvas;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_canvas);

        mCanvas= (CustomCanvas) findViewById(R.id.canvas);

        btnBackward = (ImageButton) findViewById(R.id.btn_backward);
        btnForward = (ImageButton) findViewById(R.id.btn_forward);
        btnClear = (ImageButton) findViewById(R.id.btn_clear);
        btnSave = (ImageButton) findViewById(R.id.btn_save);
        btnEraser = (ImageButton) findViewById(R.id.btn_eraser);



        btnBackward.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mCanvas.backward();

            }
        });

        btnForward.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mCanvas.forward();

            }
        });

        btnClear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mCanvas.clearCanvas();

            }
        });

        btnEraser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mCanvas.erase();
                Toast.makeText(CanvasActivity.this,"未实现",Toast.LENGTH_SHORT).show();
            }
        });

        btnSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                String path=mCanvas.saveToLocal();

                Toast.makeText(CanvasActivity.this,"保存位置为："+path,Toast.LENGTH_LONG).show();

            }
        });


    }
}
